

import pygame
from Base import Base

PLANE_PADDING=10

# 继承碰撞精灵
class MyPlane(Base):

    def __init__(self,bg_size):

        Base.__init__(self,"me1",["me_destroy_1","me_destroy_2","me_destroy_3","me_destroy_4"],bg_size)

        # 加载图片
        self.image2 = pygame.image.load("images/me2.png")

        # 设置飞机宽高
        plane_rect=self.rect 

        rect_width,rect_height = plane_rect.width,plane_rect.height

        self.width,self.height =rect_width,rect_height

        # 设置飞机位置
        # plane_rect.left,plane_rect.top = (bg_size[0] - rect_width)//2, bg_size[1] - rect_height - PLANE_PADDING
        self.reset()

        self.speed = 10

        self.currentLives= self.lives=3

    #  没有 this， 全是 self ，并且要传入参数
    def move_up(self):
        
        plane_rect=self.rect

        if plane_rect.top>PLANE_PADDING:
            plane_rect.top-=self.speed

        else:
            plane_rect.top=PLANE_PADDING

    def move_down(self):
        
        plane_rect=self.rect
    
        if plane_rect.top<self.bgH-self.height-PLANE_PADDING:
            plane_rect.top+=self.speed

        else:
            plane_rect.top=self.bgH -  self.height - PLANE_PADDING
    
    def move_left(self):
        
        plane_rect=self.rect
        
        if plane_rect.left>-self.width/2:
            plane_rect.left-=self.speed

        else:
            plane_rect.left=-self.width/2

    
    def move_right(self):
        
        plane_rect=self.rect
        
        if plane_rect.left<self.bgW - self.width/2 :
            plane_rect.left+=self.speed

        else:
            plane_rect.left=self.bgW - self.width/2 


    def reset(self):

        self.actived=True
        
        plane_rect=self.rect 
        plane_rect.left,plane_rect.top = (self.bgW - plane_rect.width)//2, self.bgH - plane_rect.height - PLANE_PADDING
